package com.school;

import java.util.Scanner;

public class Stringdemo4 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int money;
        //1.输入金额
        while(true){
            System.out.println("请输入一个金额");
            money=sc.nextInt();
            if(money>=0&&money<=999999){
                break;
            }else{
                System.out.println("输入错误，请重新输入");
            }
        }
        //2。遍历每一位数字并转成中文 获取金额每一位上的数字
        String moneystr="";//用来存储拼接的字符串
        while(true){
            int ge=money%10;
            money=money/10;
           //打印没用 我需要拼接起来 System.out.println(getCapitalNumber(ge));
            moneystr=getCapitalNumber(ge)+moneystr;//可以通过调整这两个的顺序来决定大写数字的顺序
            if(money==0){
                break;
            }
        }
        //3.在前面补零，补成七位
        int count=7-moneystr.length();//需要补的零的个数
        for (int i = 0; i < count; i++) {
            moneystr="零"+moneystr;
        }

        //4.插入单位
        //所以需要一个表来获取单位
        String[] arr={"佰","拾","万","仟","佰","拾","元"};
        String unit="";//用来存储单位
        for (int i = 0; i < moneystr.length(); i++) {
            unit+=moneystr.charAt(i)+arr[i];
        }


        System.out.println(unit);


    }

    public static String getCapitalNumber(int number){
        String[] arr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return arr[number];
    }



}
